package com.woniu.adopt_web.mapper;

import com.woniu.adopt_web.entity.Message;
import com.woniu.adopt_web.entity.Pet;
import com.woniu.adopt_web.entity.User;
import com.woniu.adopt_web.vo.UserVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(User record);

    User selectByPrimaryKey(Integer id);

    List<User> selectAll();

    int updateByPrimaryKey(UserVo record);

    UserVo selectUserByName(String username);

    @Insert("insert into t_user (username,password,name,email,insert_time,update_time)values(#{username},#{password},#{username},#{email},#{insertTime},#{insertTime})")
    int insertUserByRegister(UserVo userVo);

    List<Pet> selectPetColList(@Param("uid") Integer uid);


    void updateApply(@Param("uid") Integer uid, @Param("message") String message,@Param("status")Integer status);

    @Update("update t_apply set status=-1,update_time=now() where user_id=#{uid} and status=0")
    void delApply(@Param("uid") Integer uid);

    //暂时不考虑申请被拒绝存在多条申请记录的处理
    @Select("select status from t_apply where user_id=#{uid} and status!=-1")
    Integer selectMessageStatusByUid(@Param("uid") Integer uid);

    @Insert("insert into t_apply (user_id,message,insert_time,update_time) values (#{uid},#{message},now(),now())")
    void insertApply(@Param("uid") Integer uid, @Param("message") String message);

    @Select("select message from t_apply where user_id=#{value}")
    String queryMessageByUid(Integer uid);

    @Select("select * from t_message where user_id = #{id} order by insert_time desc")
    List<Message> selectMessageListByUid(Integer id);

    @Update("update t_message set message_state = 1 where user_id = #{uid}")
    int updateMssageByUid(int uid);

    @Select("select count(id) from t_message where user_id = #{id} and message_state = 0")
    int selectUnRead(Integer id);
}